package com.touch.client.forms;

import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import javax.media.opengl.GLAutoDrawable;
import javax.media.opengl.GLEventListener;
import com.touch.jgloo.owt.JGLButton;
import com.touch.jgloo.owt.JGLComponent;
import com.touch.jgloo.owt.JGLFrame;
import com.touch.jgloo.owt.JGLPane;

public class CharSelectGLEvents implements GLEventListener, MouseListener
{
	public JGLButton bChar[] = new JGLButton[3];	
	protected JGLButton bCancel;
	public JGLPane pChar[] = new JGLPane[3];
	public JGLFrame fCharSelect;
	
	public void display(GLAutoDrawable arg0) 
	{	
		fCharSelect.render();
	}
	public void init(GLAutoDrawable arg0) 
	{
		//build the char select
		fCharSelect = new JGLFrame("Character Selection", 400, 300);
		bCancel = new JGLButton("Cancel", 120, 25);
		bChar[0] = new JGLButton("", 120, 25);
		bChar[1] = new JGLButton("", 120, 25);
		bChar[2] = new JGLButton("", 120, 25);
		pChar[0] = new JGLPane(96, 96);
		pChar[1] = new JGLPane(96, 96);
		pChar[2] = new JGLPane(96, 96);
		
		fCharSelect.add(bCancel);
		fCharSelect.add(bChar[0]);
		fCharSelect.add(bChar[1]);
		fCharSelect.add(bChar[2]);
		fCharSelect.add(pChar[0]);
		fCharSelect.add(pChar[1]);
		fCharSelect.add(pChar[2]);
		
		pChar[0].setPosition(20, 30, 0);
		bChar[0].setPosition(10, 200, 0);
		pChar[1].setPosition(148, 30, 0);
		bChar[1].setPosition(138, 200, 0);
		pChar[2].setPosition(276, 30, 0);
		bChar[2].setPosition(266, 200, 0);
		bCancel.setPosition(260, 270, 0);		
	}
	public void reshape(GLAutoDrawable arg0, int arg1, int arg2, int arg3, int arg4) 	{}
	public void displayChanged(GLAutoDrawable arg0, boolean arg1, boolean arg2)			{}
	public void mouseClicked(MouseEvent e) 
	{	
		fCharSelect.mouseClicked(e);
		bChar[0].mouseClicked(e);
		bChar[1].mouseClicked(e);
		bChar[2].mouseClicked(e);
		bCancel.mouseClicked(e);		
		if(JGLComponent.getSelected() == bCancel.getIndex())
			fCharSelect.setVisible(false);
	}
	public void mouseEntered(MouseEvent e) 	{}
	public void mouseExited(MouseEvent e) 	{}
	public void mousePressed(MouseEvent e) 	
	{	
		fCharSelect.mousePressed(e);
	}
	public void mouseReleased(MouseEvent e)
	{	
		fCharSelect.mouseReleased(e);
	}
}
